import streamlit as st
from typing import List, Dict
from datetime import datetime

class SidebarComponent:
    """侧边栏组件"""
    @staticmethod
    def render_model_selector(
        models: List[str],
        current_model: str
    ) -> Dict:
        """渲染模型选择器和设置"""
        with st.sidebar:
            st.header("聊天设置")
            
            # 模型选择
            selected_model = st.selectbox(
                "选择模型",
                models,
                index=models.index(current_model) if current_model in models else 0
            )
            
            # 温度设置
            temperature = st.slider(
                "温度",
                min_value=0.0,
                max_value=1.0,
                value=0.7,
                step=0.1,
                help="较高的值会使输出更加随机，较低的值会使输出更加集中和确定"
            )
            
            # 最大长度设置
            max_length = st.number_input(
                "最大长度",
                min_value=100,
                max_value=4096,
                value=2000,
                help="生成文本的最大长度"
            )
            
            return {
                "model": selected_model,
                "temperature": temperature,
                "max_length": max_length
            }
    
    @staticmethod
    def render_session_manager():
        """渲染会话管理器"""
        with st.sidebar:
            st.header("会话管理")
            
            # 新建会话按钮
            if st.button("新建会话"):
                st.session_state.messages = []
                st.session_state.current_session = datetime.now().strftime(
                    "%Y%m%d_%H%M%S"
                )
            
            # 清空会话按钮
            if st.button("清空当前会话"):
                st.session_state.messages = [] 